{{ with .Site.Params.algolia_docsearch }}
<!-- scripts for algolia docsearch -->
{{ end }}
{{/* sidebar splitter */}}
<!--script src="https://unpkg.com/split.js/dist/split.min.js"></script-->
<script src="/js/split-1.6.0.js" integrity="sha384-0blL3GqHy6+9fw0cyY2Aoiwg4onHAtslAs4OkqZY7UQBrR65/K4gI+hxLdWDrjpz"></script>
<script>
  let splitInstance = null;

  function enableSplitter(mediaQuery) {
    if (mediaQuery.matches) {
      if (!splitInstance) {
        splitInstance = Split(["#sidebarnav", "#maindoc"], {
          sizes: [20, 80],
          minSize: 100,
        });
      }
    } else {
      if (splitInstance) {
        splitInstance.destroy();
        splitInstance = null;
      }
    }
  }

  const screenWidthMediaQuery = window.matchMedia("(min-width: 768px)");

  const eleNav = document.getElementById("sidebarnav");
  if (eleNav !== null) {
    enableSplitter(screenWidthMediaQuery);
    screenWidthMediaQuery.addListener(enableSplitter);
  }
</script>

{{/* copy-and-paste helper for codenew shortcode */}}
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
  {{- $toastrJs := resources.Get "js/toastr-2.1.4.min.js" | minify | fingerprint -}}
  {{- if hugo.IsProduction -}}
    <script async src="{{ $toastrJs.RelPermalink }}"></script>
  {{- else -}}
    <script async src="{{ $toastrJs.RelPermalink }}"></script>
  {{- end -}}

<script type="text/javascript">
function copyCode(elem) {
  if (document.getElementById(elem)) {
    if (navigator.clipboard) {
      navigator.clipboard.writeText(document.getElementById(elem).textContent).then(
        function () {
          toastr.options = {
            closeButton: true,
            progressBar: true,
            positionClass: "toast-bottom-center", 
            timeOut: 2000, 
            preventDuplicates: true,   
            newestOnTop: true          
          };
          toastr.success("{{i18n "toast_success_copycode"}}" + elem, "{{i18n "success_copy_to_clipboard"}}");
        },
        function () {
          toastr.options = {
            closeButton: true,
            progressBar: true,
            positionClass: "toast-bottom-center", 
            timeOut: 2000, 
            preventDuplicates: true,  
            newestOnTop: true         
          };
          toastr.error("{{i18n "toast_failure_copycode"}}" + elem, "{{i18n "error_copy_to_clipboard"}}");
        }
      );
    } else {
      toastr.options = {
        closeButton: true,
        progressBar: true,
        positionClass: "toast-bottom-center", 
        timeOut: 2000,
        preventDuplicates: true,  
        newestOnTop: true         
      };
      toastr.warning("{{i18n "browser_clipboard_support_warning"}}", "{{i18n "warning_copy_to_clipboard"}}");
    }
  }
}
</script>
{{- end -}}

{{/* JavaScript detector */}}
{{- if hugo.IsProduction -}}
  {{- $jsDetect :=  resources.Get "js/detect-js.js" | minify | fingerprint -}}
<script defer src="{{ $jsDetect.RelPermalink }}" integrity="{{ $jsDetect.Data.Integrity }}" crossorigin="anonymous"></script>
{{- else -}}
  {{- $jsDetect := resources.Get "js/detect-js.js" -}}
<script defer src="{{ $jsDetect.RelPermalink }}"></script>
{{- end -}}
